#include <stdio.h>
#include <unistd.h> //接口函数的头文件
#include <assert.h>
#include <stdlib.h>
#include <sys/wait.h>
int main()
{
  printf("begin...\n");
  printf("begin...\n");
  printf("begin...\n");
  printf("begin...\n");
  //调用接口函数
 pid_t id = fork();
 if(id == 0)
 {//child
   extern char **environ;
     printf("我是子进程：%d\n",getpid());
     char* const myargv[]= {
       "ls",
       "-a",
       "-l",
       NULL
     };
     //自定义环境变量
    // char *const myenv[] ={
    //   "MYENV=YouCanSeeMe",
    //   NULL
    // };
    // putenv("MYENV=YouCanSeeMe");
     execle("./exec/otherproc","otherproc",NULL,environ);
    // execle("./exec/otherproc","otherproc",NULL,myenv);
    // execl("./exec/otherproc","otherproc",NULL); //调用自己写的程序
    // execvp("ls",myargv);
   // execlp("ls","ls","-a","-l",NULL);
    // execlp("ls","-a","-l",NULL);
    // execv("/bin/ls",myargv);
   // int ret = execl("/bin/ls","ls","-a","-l",NULL); //调用成功无返回值，失败返回-1
   // int ret = execl("/bin/ls","ls","-a -l",NULL); //调用失败，不存在这样的选项
// int ret = execl("/bin/ls","lsssssss","-a -l",NULL); //execl替换失败，原来的代码和数据不会被执行，即后面的代码不会被执行，返回-1
    // int ret = execl("/bin/ls","ls","-al",NULL); //调用成功无返回值，失败返回-1
   // assert(ret != -1); 
    // (void)ret;  //execl调用失败无返回值,这样写的目的防止编译不通过
     exit(1);
  }
 sleep(5);
 //father
 int status = 0;
 printf("我是父进程：%d\n",getpid());
 waitpid(id,&status,0); //等待子进程
  printf("child exit code:%d\n",WEXITSTATUS(status));
  return 0;
}
